﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BCGC.BLL.Helper;
using BCGC.BLL.MailManager;

public partial class Admin_PrivateMessage_edit_privateMessage : AdminBasePage
{
    private int ID
    {
        get
        {
            if (string.IsNullOrEmpty(HttpContext.Current.Request.QueryString["id"]) == false)
                return Convert.ToInt32(HttpContext.Current.Request.QueryString["id"]);

            return -1;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindUser();
            BindEditableData();
        }
    }

    private void BindEditableData()
    {
        PrivateMessage message = PrivateMessage.GetPrivateMessageByMessageID(ID);
        if (message != null)
        {
            fckContent.Value = Server.HtmlDecode(message.Content);
            chkActive.Checked = message.IsActive;
            chkIsMarketPlaceMessage.Checked = message.IsMarketPlaceMessage;
            chkIsRead.Checked = message.IsRead;
            chkIsSendEmail.Checked = message.IsSendEmail;
            txtEmailId.Text = message.ReceiverEmailID;
            ddlToUser.SelectedItem.Value = message.ReceiverID.ToString();
            txtDate.Text = message.SendDate.ToShortDateString();
            ddlFromUser.SelectedItem.Value = message.SenderID.ToString();
            txtSubject.Text = message.Subject;
        }
    }
    private void BindUser()
    {
        ddlFromUser.Items.Add(new ListItem("Shahriar", "3"));
        ddlToUser.Items.Add(new ListItem("Shahriar", "3"));
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        PrivateMessage message = PrivateMessage.GetPrivateMessageByMessageID(ID);
        if (message != null)
        {
            message.Content = Server.HtmlEncode(fckContent.Value);
            message.IsActive = chkActive.Checked;
            message.IsMarketPlaceMessage = chkIsMarketPlaceMessage.Checked;
            message.IsRead = chkIsRead.Checked;
            message.IsSendEmail = chkIsSendEmail.Checked;
            message.ReceiverEmailID = txtEmailId.Text;
            message.ReceiverID = Convert.ToInt32(ddlToUser.SelectedItem.Value);
            message.ReceiverName = ddlToUser.SelectedItem.Text;
            message.SendDate = Convert.ToDateTime(txtDate.Text);
            message.SenderID = Convert.ToInt32(ddlFromUser.SelectedItem.Value);
            message.SenderName = ddlFromUser.SelectedItem.Text;
            message.Subject = txtSubject.Text;
            if (message.Save())
            {
                uccResponse.SetSuccessMessage("PrivateMessage successfuly saved");
            }
            else
            {
                uccResponse.SetFailMessage("Failed to save PrivateMessage");
            }
        }
    }
}
